﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;

namespace Nature.Core.DDD.RepositoryContext
{
    public class ThreadDbContextStorageContainer<T> : IDbContextStorageContainer<T> where T : class,new()
    {
        private string _key = typeof(T).Name + "__default_dbcontext";
        public T GetDbContext()
        {

            return CallContext.GetData(_key) as T;
        }

        public void Store(T dbContext)
        {
            CallContext.SetData(_key, dbContext);
        }

        public void Clear()
        {
            CallContext.FreeNamedDataSlot(_key);
        }
    }
}
